<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" :inline="true" v-show="showSearch">

      <el-form-item prop="id">
        <el-input v-model="queryParams.id" placeholder="Pls input id" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item prop="type">
        <el-input v-model="queryParams.type" placeholder="Pls input Type" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item prop="ades">
        <el-input v-model="queryParams.ades" placeholder="Pls input Ades" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item prop="status">
        <el-select v-model="queryParams.status" placeholder="Select Status" clearable>
          <el-option v-for="dict in dict.type.status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item prop="source">
        <el-select v-model="queryParams.source" placeholder="Select Status" clearable>
          <el-option v-for="dict in dict.type.emr_source" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">Search</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">Reset</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">

      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['ade:standard:export']">Export</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-share" size="mini" @click="handleCompare">Compare</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="standardList">
      <el-table-column label="ID" align="center" width="60" prop="id" />
      <el-table-column label="Content" align="left" prop="content" show-overflow-tooltip />
      <el-table-column label="Ades" align="left" prop="ades" show-overflow-tooltip />

      <el-table-column label="NAG" align="center">
        <el-table-column label="En" align="left" width="42" prop="nagAdesEnireRes" />
        <el-table-column label="Ds" align="left" width="42" prop="nagAdesDeepseekRes" />
        <el-table-column label="Gp" align="left" width="42" prop="nagAdesGptRes" />
        <el-table-column label="Qw" align="left" width="42" prop="nagAdesQwenRes" />
      </el-table-column>


      <el-table-column label="SAG" align="center">
        <el-table-column label="En" align="left" width="42" prop="adesEnireRes" />
        <el-table-column label="Ds" align="left" width="42" prop="adesDeepseekRes" />
        <el-table-column label="Gp" align="left" width="42" prop="adesGptRes" />
        <el-table-column label="Qw" align="left" width="42" prop="adesQwenRes" />
      </el-table-column>

      <el-table-column label="RAG" align="center">
        <el-table-column label="En" align="left" width="42" prop="ragAdesEnireRes" />
        <el-table-column label="Ds" align="left" width="42" prop="ragAdesDeepseekRes" />
        <el-table-column label="Gp" align="left" width="42" prop="ragAdesGptRes" />
        <el-table-column label="Qw" align="left" width="42" prop="ragAdesQwenRes" />
      </el-table-column>

      <el-table-column label="Status" align="center" width="100" prop="status">

        <template slot-scope="scope">
          <dict-tag :options="dict.type.status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <!--
         <el-table-column label="Source" align="center" width="100" prop="source" show-overflow-tooltip/>
         -->
      <el-table-column label="Update Time" align="center" width="140" prop="updateTime" />
      <el-table-column label="Actions" align="center" width="70" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)" ></el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!--Standard 详情页面-->
    <el-dialog :visible.sync="showDialog" @close="handleCancel" width="80%" :title="'Standard Detail'">
      <standard-detail-dialog v-if="selectedId" :id="selectedId" />
    </el-dialog>
  </div>
</template>

<script>
import { listStandard, startCompare } from "@/api/ade/standard";
import StandardDetailDialog from "@/views/ade/standard/detail.vue";

export default {
  name: "Standard",
  dicts: ['status', 'emr_source'],
  components: {
    StandardDetailDialog,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 标准数据集表格数据
      standardList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 12,
        year: null,
        month: null,
        type: null,
      },
      //Standard 详情对话框参数
      showDialog: false,
      selectedId: null,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询标准数据集列表 */
    getList() {
      this.loading = true;
      listStandard(this.queryParams).then(response => {
        this.standardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查看标准数据集详情 */
    handleDetail(row) {
      this.selectedId = row.id;
      this.showDialog = true;
    },
    handleCancel() {
     this.selectedId = null;
      this.showDialog = false;
    },  
    /** 开始比对分析结果 */
    handleCompare() {
      startCompare().then(response => {
        if (response.data) {
          this.$modal.msgSuccess("The comparison has commenced. Please be patient and wait...");
        } else {
          this.$modal.alert("The previous comparison task hasn't been completed yet. Please be patient and wait...");
        }
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('ade/standard/export', {
        ...this.queryParams
      }, `standard_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>
.el-form-item {
  margin-bottom: 10px;
}
</style>